﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SoftwareEngineering.Modeling
{
  internal class LookupImpl<TKey, TElement> 
    : ILookup<TKey, TElement>
  {
    public LookupImpl()
    {
      Groupings = new Dictionary<TKey, GroupingImpl<TKey, TElement>>();
    }

    public Dictionary<TKey, GroupingImpl<TKey, TElement>> Groupings { get; set; }

    public bool Contains(TKey key)
    {
      return Groupings.ContainsKey(key);
    }

    public int Count
    {
      get { return Groupings.Count; }
    }

    public IEnumerable<TElement> this[TKey key]
    {
      get { return Groupings[key]; }
    }

    public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator()
    {
      return Groupings.Values.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
      return GetEnumerator();
    }
  }

  internal class GroupingImpl<TKey, TElement> 
    : IGrouping<TKey, TElement>
  {
    public List<TElement> Elements { get; set; }

    public TKey Key
    {
      get;
      set;
    }

    public IEnumerator<TElement> GetEnumerator()
    {
      return Elements.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
      return GetEnumerator();
    }
  }
}
